package com.cyzy.utils;

import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class AliyunUtil {
     public static String AccessKeyId;
    public static String AccessKeySecret;
    public static String endpoint;
    public static String imgFile;


    //静态代码块，只会读取一次
    static {
        //读取配置文件
        Properties properties = new Properties();

        try {
            InputStream resourceAsStream = AliyunUtil.class.getClassLoader().getResourceAsStream("Aliyun.properties");
            properties.load(resourceAsStream);
            AccessKeyId = properties.getProperty("aliyun.AccessKeyId");
            AccessKeySecret = properties.getProperty("aliyun.AccessKeySecret");
            endpoint = properties.getProperty("aliyun.endpoint");
            imgFile = properties.getProperty("file.imgFile");
            System.out.println("AccessKeyId: " + AccessKeyId);
            System.out.println("文件保存路径: " + imgFile);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}



//    public static Connection getConnection() throws SQLException {
//        return DriverManager.getConnection(url,username,password);
//    }
//
//    //关闭方法
//    public static void close(Connection conn, Statement stmt, ResultSet rs) {
//        try {
//            if(rs != null){
//                rs.close();
//            }
//        } catch (SQLException e) {
//            throw new RuntimeException(e);
//        }
//        try {
//            if(stmt != null){
//                stmt.close();
//            }
//        } catch (SQLException e) {
//            throw new RuntimeException(e);
//        }
//        try {
//            if(conn != null){
//                conn.close();
//            }
//        } catch (SQLException e) {
//            throw new RuntimeException(e);
//        }
//    }
//}
